// pages/parentFeedback/parentFeedback.js
var api = require('../../utils/api.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    idx: '',
    idx1: '',
    schollArr: [],
    projectArr: [],
    campus_id: '',
    project_id: '',
    content: ''

  },

  //学校切换
  changeSchool(e) {
    // console.log(e.currentTarget.dataset.id)
    var idx = e.detail.value;
    var nowArr = this.data.schollArr[idx];
    var campus_id = nowArr.id
    //console.log(campus_id)
    this.setData({
      idx,
      campus_id
    })
  },


  //项目切换
  changeProject(e) {
    var idx1 = e.detail.value;
    var nowArr = this.data.projectArr[idx1];
    var project_id = nowArr.id;
    // console.log(project_id)
    this.setData({
      idx1,
      project_id
    })
  },

  //获取校区、项目
  getSchool() {
    api.fetchApi('student/getcenter_info', { token: wx.getStorageSync('token') }).then(res => {
      //console.log(res)
      var schollArr = res.campus;
      var projectArr = res.project;
      this.setData({
        schollArr,
        projectArr
      })

    })
  },

  //留言
  notice(e) {
    var content = e.detail.value
    console.log(content)
    this.setData({
      content
    })
  },
  //提交留言
  handleSubmit() {
    if (!this.data.campus_id) {
      api.showToast('请选择校区', 'http://qnwmfx.laigl.com/iconimg/warn.png')
      return
    }
    if (!this.data.project_id) {
      api.showToast('请选择项目', 'http://qnwmfx.laigl.com/iconimg/warn.png')
      return
    }
    if (!this.data.content) {
      api.showToast('请填写内容', 'http://qnwmfx.laigl.com/iconimg/warn.png')
      return
    }
    var params = {
      token: wx.getStorageSync('token'),
      campus_id: this.data.campus_id,
      project_id: this.data.project_id,
      content: this.data.content
    }
    api.fetchApi('student/get_center', params).then(res => {
      api.showToast('提交成功')
      setTimeout(()=>{
        wx.navigateBack({
          
        })
      },1500)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getSchool()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})